package com.yxh.util;

import com.alibaba.fastjson.annotation.JSONField;

import javax.xml.bind.annotation.XmlRootElement;

/**
 * Created by pc on 2017/2/21.
 */
@XmlRootElement
public class Response<T> {
    @JSONField(ordinal = 1)
    Long errCode;
    @JSONField(ordinal = 2)
    String msg;
    @JSONField(ordinal = 3)
    T data;

    public static Response returnResponse(String msg) {
        return new Response(msg);
    }

    public static Response returnResponse(Long errCode, String msg, Object data) {
        return new Response(errCode, msg, data);
    }

    public static Response returnResponse(Long errCode, Object data) {
        return new Response(errCode, data);
    }

    public static Response returnResponse(Long errCode, String msg) {
        return new Response(errCode, msg);
    }

    public static Response returnResponse(APIErrorCode code) {
        return new Response(code.getValue(), code.getDesc());
    }

    private Response(Long errCode, String msg, T data) {
        this.errCode = errCode;
        this.msg = msg;
        this.data = data;
    }

    private Response(Long errCode, T data) {
        this.errCode = errCode;
        this.data = data;
    }

    private Response(String msg) {
        this.msg = msg;
    }

    private Response(Long errCode, String msg) {
        this.errCode = errCode;
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "Response{" +
                "errCode='" + errCode + '\'' +
                ", msg='" + msg + '\'' +
                ", data='" + data + '\'' +
                '}';
    }

    public Long getErrCode() {
        return errCode;
    }

    public void setErrCode(Long errCode) {
        this.errCode = errCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
